package com.cube.truthseer.service.impl;

import com.cube.truthseer.common.entity.dto.EmailInfoDTO;
import com.cube.truthseer.service.IEmailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class SmsServiceImpl implements IEmailService{
    @Value("${spring.mail.username}")
    private String UserName;//获得配置文件中的username
    @Autowired
    private JavaMailSender mailSender;//发送邮件的bean
    @Override
    public void sendMessage(EmailInfoDTO emailInfoDTO) {
        log.info("emailDTO:{}",emailInfoDTO);

        String title="VisionTag邮箱验证";
        //正文内容
        String text = "你的验证码为" + emailInfoDTO.getTemplateParams().get("code") + "，有效时间为5分钟，请尽快使用并且不要告诉别人。";
        SimpleMailMessage msg=new SimpleMailMessage();
        //发送邮件的邮箱
        msg.setFrom(UserName);
        //发送到哪里
        msg.setTo(String.valueOf(emailInfoDTO.getEmail()));
        //邮件标题
        msg.setSubject(title);
        //邮件文本
        msg.setText(text);
        mailSender.send(msg);
        log.info("msg是:{}",msg);
    }
}
